//
//  SLTabBarItem.swift
//  Sina15
//
//  Created by 盼 on 16/4/16.
//  Copyright © 2016年 pan. All rights reserved.
//

import UIKit

class SLTabBarItem: UITabBarItem {

    //重写tabBarItem的badge属性，一旦修改badgeValue，就给当前tabBarButton的badgeValue修改背景图
  override var badgeValue: String? {

    didSet {
        let target = valueForKey("_target") as! SLMainController
        
        for subView in target.tabBar.subviews {
            
            if subView.isKindOfClass(NSClassFromString("UITabBarButton")!) {
                for sub in subView.subviews {
                    
                    if sub.isKindOfClass(NSClassFromString("_UIBadgeView")!) {
                        
                        for bgSub in sub.subviews {
                            
                            if bgSub.isKindOfClass(NSClassFromString("_UIBadgeBackground")!) {
                                
                                bgSub.setValue(UIImage(named: "main_badge"), forKey: "_image")
                            }
                        }
                    }
                }
            }
        }
    }
    
    }
}
